package com.lianzai.shop.controller;

import com.lianzai.shop.model.Shop;
import com.lianzai.common.controller.BaseController;
import com.lianzai.common.utils.PageUtils;
import com.lianzai.common.utils.Query;
import com.lianzai.shop.service.OrderService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/shop/order")
public class OrderController extends BaseController {

    @Autowired
    OrderService orderService;

    @GetMapping()
    String order(Model model){
        List<Map<String, String>> statusList = new ArrayList<>();
        Map<String, String> statusMap = new HashedMap();
        statusMap.put("id","0");
        statusMap.put("name","未付款");
        statusList.add(statusMap);
        Map<String, String> status1Map = new HashedMap();
        status1Map.put("id","1");
        status1Map.put("name","已付款");
        statusList.add(status1Map);
        Map<String, String> status2Map = new HashedMap();
        status2Map.put("id","2");
        status2Map.put("name","付款失败");
        statusList.add(status2Map);
        model.addAttribute("statusList",statusList);

        List<Map<String, Object>> minuteList = orderService.minuteList();
        model.addAttribute("minuteList",minuteList);
        return "shop/order/list";
    }

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        List<Shop> carInfoList = orderService.list(query);
        int total = orderService.count(query);
        PageUtils pageUtils = new PageUtils(carInfoList, total);
        return pageUtils;
    }

}
